package com.lucky.common.util;

import cn.hutool.core.date.DateUtil;
import cn.hutool.core.date.LocalDateTimeUtil;
import cn.hutool.core.util.DesensitizedUtil;
import org.apache.commons.lang3.StringUtils;

import java.math.BigDecimal;
import java.math.RoundingMode;
import java.text.DecimalFormat;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.util.Date;
import java.util.Map;


public class AppUtil {

	private static final String formTime = "yyyy-MM-dd HH:mm:ss";
	private static final String formDate = "yyyy-MM-dd";
	private static final DecimalFormat formatAmt = new DecimalFormat("###,###,###,##0.00");

	public static String br(String str) {
		return str.replaceAll(",", "<br/>");
	}
	public static String xss(String str) {
		return XssUtils.replaceUnXssAll(str);
	}
	public static Object xss(Object obj) {
		return XssUtils.replaceUnXss(obj);
	}
	public static Map<String, Object> xss(Map<String, Object> map) {
		return XssUtils.replaceUnXss(map);
	}
	
	public static String fStr(String str) {
		return xss(str);
	}

	public static String phone(String str) {

		return DesensitizedUtil.mobilePhone(str);
//		return PhoneUtil.hideBetween(str).toString();
	}


	public static String fAmt(BigDecimal amt) {
		return formatAmt.format(amt);
	}
	
	public static String fTime(Date now) {
		return DateUtil.format(now,  formTime);
	}
	public static String fDate(Date now) {
		return DateUtil.format(now,  formDate);
	}

	public static String fTime(LocalDateTime now) {
		return LocalDateTimeUtil.format(now,  formTime);
	}
	public static String fDate(LocalDateTime now) {
		return LocalDateTimeUtil.format(now,  formDate);
	}
	public static String fDate(LocalDate now) {
		return LocalDateTimeUtil.format(now,  formDate);
	}

	public static BigDecimal abs(BigDecimal a1) {
		return a1.abs().setScale(2, RoundingMode.HALF_UP);
	}
	
	public static BigDecimal add(BigDecimal a1, BigDecimal a2) {
		return a1.add(a2).setScale(2, RoundingMode.HALF_UP);
	}
	
	public static BigDecimal sub(BigDecimal a1, BigDecimal a2) {
		return a1.subtract(a2).setScale(2, RoundingMode.HALF_UP);
	}
	
	public static BigDecimal x(BigDecimal a1, BigDecimal a2) {
		return a1.multiply(a2).setScale(2, RoundingMode.HALF_UP);
	}
	
	public static BigDecimal div(BigDecimal a1, BigDecimal a2) {
		return a1.divide(a2).setScale(2, RoundingMode.HALF_UP);
	}
	
	public static String upper(String s){
		return StringUtils.upperCase(s);
	}
	public static String lower(String s){
		return StringUtils.lowerCase(s);
	}


	public static void main(String[] args) {
		String str = fTime(new Date());
		System.out.println(str);
	}
}





















